package com.houzehui.mncommodity.service.impl;

import com.houzehui.mncommodity.entity.Commodity;
import com.houzehui.mncommodity.entity.Commoditypromotion;
import com.houzehui.mncommodity.mapper.CommodityMapper;
import com.houzehui.mncommodity.service.ICommodityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.houzehui.mncommodity.service.ICommoditypromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author houzehui
 * @since 2022-04-08
 */
@Service
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements ICommodityService {


    @Autowired
    ICommodityService iCommodityService;

    @Autowired
    ICommoditypromotionService iCommoditypromotionService;

    @Override
    public int add(Commodity commodity) {
        //增加
        iCommodityService.save(commodity);


        List<Integer> proidss = commodity.getProidss();
        System.err.println(proidss);
        for (Integer integer : proidss) {
            Commoditypromotion commoditypromotion = new Commoditypromotion().setCid(commodity.getId()).setPid(integer);
            System.err.println(commoditypromotion);
            iCommoditypromotionService.save(commoditypromotion);
        }


        return 1;
    }
}
